package com.showapi.app.dynamic

import com.showapi.app.util.CommonUtil
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.context.ApplicationContext

public abstract class BaseNode {
	static Logger log= LoggerFactory.getLogger(BaseNode.class)
	protected Map node_cfg=[:]		//存储本处理器的配置
	protected BaseLine line
	ApplicationContext ctx

	def tryBoolean= CommonUtil.&tryBoolean
	def getRetObj= CommonUtil.&getRetObj
	def retryCallback=CommonUtil.&retryCallback
	def trimParams=CommonUtil.&trimParams
	def removeProperty= CommonUtil.&removeProperty



	//初始化
	public void   	doInitNode( ){
	}
	public boolean	doIsMatch(reqParams,lineParams){
		return true
	}
	//权重类比班级排名
	public int    	doSortWeight(reqParams,lineParams){
		return 1
	}
	public void    	doBeforeAction(reqParams,lineParams){
	}
	//做封装
	public   Map  	wrapAction(reqParams,lineParams){
		long do_before_action_time= System.currentTimeMillis()
		doBeforeAction(reqParams,lineParams)
		def ret=doAction(reqParams,lineParams)
		doAfterAction(reqParams,lineParams)

		long do_after_action_time= System.currentTimeMillis()
//		log.info "do_before_action_time :"+do_before_action_time
//		log.info "do_after_action_time :"+do_after_action_time
		return ret;
	}

	//执行具体内容
	public   Map  	doAction(reqParams,lineParams){
		return [:];
	}
	public void    	doAfterAction(reqParams,lineParams){
	}
	
	//设置stop_switch状态
	public   void  setStopLine(lineParams,boolean state=true){
		lineParams.stopLine=state
	}
	

	//取得整个流程共享map
	public   Map  getShareMap(lineParams){
		return lineParams.shareMap
	}

	def propertyMissing(pName){
//		log.info "find property:  "+pName
		return ctx.getBean(pName)
	}
	def methodMissing(String name, def args) {
		throw new Exception("cant find method "+name)
	}

}
